package capr.model;

import java.io.IOException;
import java.net.URL;
import com.md5importer.MD5Importer;
import com.md5importer.interfaces.model.IMD5Node;

/**
 * @author Ludwig Lienkamp
 * @author Yi Wang (Neakor)
 * 
 * load a mesh with the MD5Importer-Concurrent 
 * http://md5importer.googlecode.com/svn/trunk/
 */
public class LoadMD5Mesh {
	
	protected MD5Importer importer;
	protected IMD5Node mesh;
	
	/**
	 * Ludwig Lienkamp <br>
	 *
	 * load the mesh with the MD5Importer of Yi Wang
	 *
	 * @param  meshName 	name of the File
	 * @return				interface on an MD5Node
	 */
	public IMD5Node loadMesh(String meshName) {
		
		//create a importer for md5 files
		importer = new MD5Importer();

		try {
			
			//return null, if the File not found
			URL meshURL = MD5Importer.class.getClassLoader().getResource("capr/model/data/mesh/" + meshName);
	
			//load the Mesh
			mesh = importer.loadMesh(meshURL, meshName);
			
			//cleanup the importer
			importer.cleanup();
		
		} catch(IOException e) {
		
			e.printStackTrace();
		}
	
		//return the mesh as IMD5Node
		return mesh;
	}
}
